package kioschool.view.controlsimpl
{
	import flash.display.DisplayObject;
	import flash.events.MouseEvent;
	
	import kioschool.model.AbstractStep;
	import kioschool.controller.PrimaryController;
	import kioschool.view.controls.INavigationPanel;
	import kioschool.view.controls.IRegimePanel;
	
	import mx.core.ButtonAsset;

	/**
	 * Пеналь навигации, предоставляемая платформой по умолчанию
	 * 
	 * @author Akimushkin Vasiliy
	 */ 
	public class DefaultNavigationPanel implements INavigationPanel
	{
		/**
		 * Дефолтное представление
		 */ 
		private var view:DefaultNavigationPanelView = new DefaultNavigationPanelView();
		
		/**
		 * Конструктор, инициализирует слушателей кнопок смены режимов
		 */ 
		public function DefaultNavigationPanel(){
			view.next_btn.addEventListener(
				MouseEvent.CLICK,
				function(ev:MouseEvent):void {
					PrimaryController.instance.nextClick();
				}
			);
			
			view.prev_btn.addEventListener(
				MouseEvent.CLICK,
				function(ev:MouseEvent):void {
					PrimaryController.instance.backClick();
				}
			);
			
			view.clear_btn.addEventListener(
				MouseEvent.CLICK,
				function(ev:MouseEvent):void {
					PrimaryController.instance.initController();
				}
			);
			view.submit_btn.addEventListener(
				MouseEvent.CLICK,
				function(ev:MouseEvent):void{
					PrimaryController.instance.submitSolution();
				}
			);
		}
		
		public function regimeChanged(regime:int):void{
			view.submit_btn.visible = regime==PrimaryController.REGIME_CONTROL;
		}
		
		public function stepChanged(isFirst:Boolean, step:AbstractStep):void{
			view.prev_btn.enabled=!isFirst;
			view.prev_btn.mouseEnabled=!isFirst;
			if(view.prev_btn.enabled)
				view.prev_btn.alpha=1;
			else
				view.prev_btn.alpha=0.5;
			
			view.next_btn.enabled=step.next()!=null;
			view.next_btn.mouseEnabled=step.next()!=null;
			if(view.next_btn.enabled)
				view.next_btn.alpha=1;
			else
				view.next_btn.alpha=0.5;
			
//			view.submit_btn.enabled = step.next()==null;
//			view.submit_btn.mouseEnabled = step.next()==null;
//			
//			if(view.submit_btn.enabled)
//				view.submit_btn.alpha=1;
//			else
//				view.submit_btn.alpha=0.5;
		}
		
		public function getView():DisplayObject{
			return view;
		}
	}
}